/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { message } from 'antd';
import { REGISTER_COLUMNS } from '../../../index.d';
import ProForm, { ModalForm, ProFormTextArea } from '@ant-design/pro-form';
import { saveBlack, saveRemark } from '@/services/jdk/register';

interface RefuseModalProps {
  children: JSX.Element;
  successCallBack: Function;
  item: REGISTER_COLUMNS;
}

const RefuseModal: React.FC<RefuseModalProps> = ({ item, children, successCallBack }) => {
  const { user_id } = item;
  return (
    <ModalForm
      title='温馨提示'
      trigger={children}
      width={480}
      modalProps={{
        destroyOnClose: true,
      }}
      onFinish={async (values) => {
        const { code, msg } = await saveRemark({ user_id, ...values });
        if (code == 0) {
          const { code: code_, msg: msg_ } = await saveBlack({ user_id });
          if (code_ == 0) {
            message.success('禁止登录成功！');
            successCallBack();
            return true;
          }
          message.error(msg_);
          return false;
        } else {
          message.error(msg);
          return false;
        }
      }}
    >
      <h3>确定此用户禁止登录？</h3>
      <ProForm.Group>
        <ProFormTextArea
          width='xl'
          name='remark'
          placeholder='填写原因'
          allowClear
          rules={[{ required: true, message: '请填写原因' }]}
          fieldProps={{
            rows: 4,
            maxLength: 20,
          }}
        />
      </ProForm.Group>
    </ModalForm>
  );
};

export default RefuseModal;
